using System;
using FluentNHibernate.Conventions;
using FluentNHibernate.Conventions.Instances;

namespace Caramel.FluentNHibernate.Conventions
{
	public class PrimaryKeyConvention : IIdConvention
	{
		public void Apply(IIdentityInstance instance)
		{
			instance.Column("ID");

			if (instance.Property != null)
			{
				if ((instance.Property.PropertyType == typeof(int)) || (instance.Property.PropertyType == typeof(int?)))
				{
					instance.GeneratedBy.Identity();
				}

				if ((instance.Property.PropertyType == typeof(Guid)) || (instance.Property.PropertyType == typeof(Guid?)))
				{
					instance.GeneratedBy.GuidComb();
				}
			}
		}
	}
}
